package com.xiaoma.nio;

import java.nio.IntBuffer;

/**
 * 举例说明buffer的基本使用
 */
public class BasicBuffer {
    public static void main(String[] args) {
        //创建一个可以存放5个int的buffer
        IntBuffer intBuffer = IntBuffer.allocate(5);
        for (int i = 0; i < intBuffer.capacity(); i++) {
            //存数据
            intBuffer.put(i*2);
        }
        //取数据
        //将buffer读写切换
        intBuffer.flip();
        while (intBuffer.hasRemaining()){
            System.out.println(intBuffer.get());
        }
    }
}
